<!DOCTYPE html>
<html>
  <head>
    <title></title>
    <script src="../../lib/js/wrapxhr.js"></script>
  </head>
  <body>
    <textarea id="log" cols="80" rows="30">
    </textarea>
  </body>
  <script>
    function getOptions(options) { 
	var search = location.search;
	if (search && search.charAt(0) == '?') 
	    search = search.substring(1,search.length);
	var opts = search.split('&');
	for (var i = 0; i < opts.length; i++) { 
	    var pair = opts[i].split('=');
	    var key  = pair[0];
	    var val  = pair[1];
	    for (var j = 2; j < pair.length; j++) val += '=' + pair[j];
	    if (!key || key.length <= 0) continue;
	    if (!val || val.length <= 0) val = true;
	    options[key] = val;
	}
    }
    function handler(e) { 
	var xhr = e.target;
	console.log("Got status: " + xhr.readyState + "/" + xhr.statusText);
	switch (xhr.readyState) { 
	case 0: // uninitialized
	case 1: // loading 
	case 2: // loaded 
	case 3: // interactive 
	    break;
	case 4: // completed 
	    console.log("Status: " + xhr.status);
	    document.getElementById('log').innerHTML = 
		JSON.stringify(xhr.responseText, null, " ");
	    break;
	default: console.error("Failed to get response");
	}
    }
    
    var options = {
	// url: "http://dr03-lh.akamaihd.net/i/dr03_0@147056/master.m3u8?b=100-1600&rebase=on"
	url: "http://no.where/"
    };
    getOptions(options);
    var xml = new XMLHttpRequest();
    xml.onreadystatechange = handler;
    // var url = decodeURIComponent(options["url"]);
    var url = options["url"];
    xml.open("GET", url, true);
    xml.send();
  </script>
</html>
